﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArithmeticDemo
{
    public class LeeCode189
    {
        public void Start() {
            int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
            Rotate(nums, 1);
            foreach (var item in nums) {
                Console.WriteLine(item);
            }
        }
        public void Rotate(int[] nums, int k) {
            k %= nums.Length;
            reverse(nums, 0, nums.Length - 1);
            reverse(nums, 0, k - 1);
            reverse(nums, k, nums.Length - 1);
        }
        public void reverse(int[] nums, int start, int end) {
            while (start < end) {
                int temp = nums[start];
                nums[start] = nums[end];
                nums[end] = temp;
                start += 1;
                end -= 1;
            }
        }
    }
}
